<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <!-- 引入样式 -->
    <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="../app/lib/ZohoCrmHelper.js" type="text/javascript"></script>
    <script src="../app/lib/ZSDK.js" type="text/javascript"></script>
    <script src="../app/lib/jquery-1.10.2.js" type="text/javascript"></script>
    <script src="../app/lib/ZohoEmbededAppSDK.min.js" type="text/javascript"></script>
    <script src="../app/lib/axios.min.js" type="text/javascript"></script>
    <title>股权穿透</title>
</head>

<body>
<div id="app">


    <el-tree
            :empty-text="emptyText"
            :data="dataForm"
            :props="defaultProps"
            node-key="id"
            ref="tree"
            @node-click="handleNodeClick"
            highlight-current
            default-expand-all></el-tree>

</div>


</body>
</html>


<script type="text/javascript">
    const app = new Vue({
        el: '#app',
        data() {
            return {
                emptyText: '加载中',
                filterText: '',
                crmId: "",
                dataForm:[],
                defaultProps: {
                    children: 'children',
                    label: 'label'
                }
            };
        }
        ,
        mounted() {
            this.initData();
            ZOHO.embeddedApp.init();
        },
        watch: {
            filterText(val) {
                this.$refs.tree.filter(val);
            }
        },
        methods: {
            initData() {
                ZOHO.embeddedApp.on("PageLoad", function (data) {
                    app.crmId = data.EntityId;
                    app.callFunction();
                });

            },
            // 小部件调函数
            callFunction() {
                let func_name = "AccountWidget";				// 函数名
                let req_data = {"id": app.crmId};// 参数
                ZOHO.CRM.FUNCTIONS.execute(func_name, req_data)
                    .then(function (data) {

                        const str = data.details.output;
                        console.log("str=" + str);
                        app.dataForm = JSON.parse(str);
                        app.emptyText = '';
                    })
            },

            handleCheckChange(data, checked, indeterminate) {
                // console.log(JSON.stringify(data));
                // console.log(data, checked, indeterminate);
            },
            setCheckedKeys() {
                this.$refs.tree.setCheckedKeys([3]);
            },
            resetChecked() {
                this.$refs.tree.setCheckedKeys([]);
            },


            handleNodeClick(data) {
                console.log(data.id);
                window.open('https://crm.zoho.com.cn/crm/org45159478/tab/Accounts/' + data.id);
            },

        }
    });

</script>
<style>

</style>


